<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        border: 1px solid;
      }
    </style>
  </head>
  <body>
    <ul id="list">
      <li>
        abc
        <ul>
          <li>abc1</li>
          <li>abc2</li>
          <li>
            abc3
            <ul>
              <li>a</li>
              <li>b</li>
              <li>c</li>
              <li>d</li>
            </ul>
          </li>
        </ul>
      </li>
      <li>
        abd
        <ul>
          <li>abd1</li>
          <li>abd2</li>
        </ul>
      </li>
      <li>abe</li>
    </ul>
    <script>
      function totalLi(el) {
        [...el.children].forEach((item) => {
          const ul = item.children[0];
          if (ul !== undefined) {
            item.childNodes[0].data += `[${ul.children.length}]`;
            totalLi(ul);
          }
        });
      }
      totalLi(document.getElementById("list"));
    </script>
  </body>
</html>
